package cn.edu.sdyu.ie.crs.common.response;

import io.swagger.annotations.ApiModel;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.data.domain.Page;

import java.util.List;

/**
 * Created by Simon on 2020/12/10.
 */

@ApiModel("分页视图")
@Data
public class PageVO<T> {
    @Schema(description = "分页数据列表")
    private List<T> list;
    @Schema(description = "分页信息")
    private Pagination pagination;

    private PageVO(List<T> list, Integer page, Integer pageSize, Integer pageCount, Long total) {
        this.list = list;
        this.pagination = new Pagination(page, pageSize, pageCount, total);
    }

    public static PageVO getPageVO(Page page) {
        return new PageVO(page.getContent(), page.getNumber() + 1, page.getSize(), page.getTotalPages(), page.getTotalElements());
    }
}
